package com.tool.btn;

import com.tool.image.ImageMixDeal;
import com.tool.role.RoleData;
import org.come.Frame.ZhuFrame;
import org.come.Jpanel.HallucinationJpanel;
import org.come.Jpanel.SummoningCompoundJpanel;
import org.come.Jpanel.experimentCompoundJpanel;
import org.come.bean.ConfigureBean;
import org.come.bean.SummonPetBean;
import org.come.bean.itemBean;
import org.come.entity.Goodstable;
import org.come.entity.RoleSummoning;
import org.come.good.PetEquip;
import org.come.model.Configure;
import org.come.model.ItemExchange;
import org.come.model.petExchange;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.GoodsListFromServerUntil;
import org.come.until.GsonUtil;
import org.come.until.UserData;
import org.come.until.UserMessUntil;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.math.BigDecimal;
import java.util.Map;

/**
 * @author HGC<br>
 * @time 2020年1月10日 下午7:02:42<br>
 * @class 类名:SummoningCompoundBtn<br>
 */
public class experimentCompoundBtn extends MoBanBtn {

    private int caozuo;
    private experimentCompoundJpanel compoundJpanel;
    private HallucinationJpanel hallucinationJpanel;
    public experimentCompoundBtn(String iconpath, int type, Color[] colors, String text, Font font, int caozuo,
                                 experimentCompoundJpanel compoundJpanel) {
        super(iconpath, type, colors);
        setText(text);
        setFont(font);
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
        this.caozuo = caozuo;
        this.compoundJpanel = compoundJpanel;
    }

    public experimentCompoundBtn(String iconpath, int type, Color[] colors, String text, Font font, int caozuo,
                                 HallucinationJpanel hallucinationJpanel) {
        super(iconpath, type, colors);
        setText(text);
        setFont(font);
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
        this.caozuo = caozuo;
        this.hallucinationJpanel = hallucinationJpanel;
    }




    @Override
    public void chooseyes() {
        // TODO Auto-generated method stub

    }

    @Override
    public void chooseno() {
        // TODO Auto-generated method stub

    }

    @Override
    public void nochoose(MouseEvent e) {
        if (ImageMixDeal.userimg.getRoleShow().getBooth_id() != null) {
            ZhuFrame.getZhuJpanel().addPrompt2("摆摊状态不可以操作！");
            return;
        }
        if (caozuo == 1) {
            ConfigureBean allConfigure = UserMessUntil.getConfigureBean();
            Map<BigDecimal, Configure> item = allConfigure.getAllConfigure();
            Configure configure = item.get(new BigDecimal(1));
            if (UserMessUntil.getPetListTable() != null && UserMessUntil.getPetListTable().size() >= Integer.parseInt(configure.getXdzhssx())) {
                ZhuFrame.getZhuJpanel().addPrompt2("您的召唤兽可携带的数量已满！！！");
                return;
            }
            ItemExchange ItemExchange = compoundJpanel.getItemExchange();
            if (ItemExchange == null) {
                ZhuFrame.getZhuJpanel().addPrompt2("没有选中装备");
                return;
            }
            if (RoleData.getRoleData().getLoginResult().getGold().compareTo(compoundJpanel.getMoney()) < 0) {
                ZhuFrame.getZhuJpanel().addPrompt2("金额不足");
                return;
            }
            String consume = ItemExchange.getConsume();
            if (consume != null && !"".equals(consume)) {
                String[] split = consume.split("\\|");
                for (int i = 0; i < split.length; i++) {
                    if (split[i].startsWith("G")) {
                        String[] arrMoney = split[i].split("=");
                        Goodstable goodstable = UserMessUntil.getgoodstable(new BigDecimal(arrMoney[1]));
                        int needMum = Integer.parseInt(arrMoney[2]);
                        int goodNum = GoodsListFromServerUntil.getGoodNum(goodstable.getGoodsid());
                        if (needMum > goodNum) {
                            ZhuFrame.getZhuJpanel().addPrompt2("合成材料不足");
                            return;
                        }
                    }
                }
            }

            // 获取召唤兽
            itemBean itemBean = new itemBean();
            itemBean.setOpertype(100);
            itemBean.setzhuangbeiid(new BigDecimal(ItemExchange.geteId()));
            //system.out.println("ItemExchange的id是"+ItemExchange.geteId());
            String mes = Agreement.getAgreement().itemAgreement(GsonUtil.getGsonUtil().getgson().toJson(itemBean));
            //system.out.println("json是"+GsonUtil.getGsonUtil().getgson().toJson(itemBean));
            //system.out.println("服务器要收到信息了,信息是"+mes);
            // 向服务器发送信息
            SendMessageUntil.toServer(mes);
        }else if (hallucinationJpanel!=null && caozuo == 2) {
            if(!HallucinationJpanel.ishh){
                ZhuFrame.getZhuJpanel().addPrompt2("幻化材料不足");
                return;
            }
            if (RoleData.getRoleData().getLoginResult().getGold().compareTo(hallucinationJpanel.getMoney()) < 0) {
                ZhuFrame.getZhuJpanel().addPrompt2("你身上的金钱不足");
                return;
            }
            // 选择幻化的宠物
            String petsid = HallucinationJpanel.selectPet;
            String selectHHPetId = HallucinationJpanel.selectHHPet;
            if(petsid==null && petsid.equals("")) {
                ZhuFrame.getZhuJpanel().addPrompt2("你还没有此召唤兽！");
                return;
            }
            RoleSummoning pet = UserMessUntil.getPetRgid(new BigDecimal(petsid));
            if(pet.getHhschedule()!=null && !pet.getHhschedule().equals("")) {
                ZhuFrame.getZhuJpanel().addPrompt2("召唤兽已经幻化，请勿重复幻化！");
                return;
            }
            int adskin = PetEquip.getCJSID(Integer.parseInt(pet.getSummoningid()));
            UserData.uptael(hallucinationJpanel.getMoney().longValue());
            String mes = Agreement.getAgreement().petchangeAgreement("大话幻化&"+petsid+"&"+selectHHPetId+"&"+adskin+"&"+HallucinationJpanel.selectColor);
            SendMessageUntil.toServer(mes);
        }
    }
}
